import request from "./request";

interface AdminLoginData {
  password: string;
  username: string;
}
type PromiseRes<T> = Promise<ManageResult<T>>;
interface ManageResult<T = {}> {
  code: number;
  data: T;
  message: string;
}
interface AdminLoginRes {
  token: string;
  token_type: string;
  expires_id: number;
}
interface UsersInfoList {
  list: [];
  total: number;
  current_page: number;
  total_page: number;
  limit: number;
  action_name: string;
  column_name: [];
}
interface DepartmentInfoList {
  list: [];
  column_name: [];
  action_name: string;
  total?: number;
  current_page?: number;
  total_page?: number;
  limit?: number;
}
interface RoleInfoList {
  list: [];
  column_name: [];
  action_name: string;
  total?: number;
  current_page?: number;
  total_page?: number;
  limit?: number;
}
interface MenuInfoList {
  list: [];
  column_name: [];
  action_name: string;
  total?: number;
  current_page?: number;
  total_page?: number;
  limit?: number;
}
interface AdminInfoRes {
  menus: [];
}
interface UploadData {
  file: Object;
  folder: String;
  type: String;
}

interface AddNewCustomer {
  number: String; //客户编号
  type: String | Number; //integer 类型
  user_id: String | Number; //integer 跟进人
  name: String | Number;
  phone: String;
  qq: String;
  weixin: String;
  country: String;
  province: String;
  city: String;
  district: String;
  address: String;
  resource_url: String | Object; //资料上传json
  status: String | Number; //integer 是否有效
  gender: String | Number; //integer
  age: String | Number;
  level: String | Number;
  customer_status: String | Number; //客户状态
  is_hospital: String | Number; //是否进院
  source: String | Number; //客户来源
  industry: String | Number; //所属行业
  trading_volume: String | Number; //成交金额
  keywords: String | Number; //关键词搜索
  source_type: String | Number; //资源类型
  consult_type: String | Number; //integer 咨询类型
  hospital_id: String | Number; //integer 意向医院
  territory_attribute: String | Number; //integer 地域属性
  desc: String | Number; // 备注
}

interface AddNewUser {
  userName: String;
  password: String;
  email?: String | null;
  avater?: String;
  phone?: String;
  department_id: Number | null;
  role_id: Number | null;
  position: Number | null;//0：超管/1：管理/2：员工
  status?: Boolean;//true：启用/false：禁用
}

interface CustomerList {
  list: [];
  column_name: [];
  total?: number;
  current_page?: number;
  total_page?: number;
  limit?: number;
}
interface CustomerListParams {
  id: String;
  name: String;
  create_time: String;
  page?: Number;
  limit: Number;
}

//登录
export const loginApi = (data: AdminLoginData): PromiseRes<AdminLoginRes> =>
  request.post("login", data);
/**
 * 用户管理
 *
 * */
//用户列表
export const getUsersInfoList = (): PromiseRes<UsersInfoList> =>
  request.get("user/list");
// 用户列表-新增用户
export const addNewUser = (
  data: AddNewUser
): PromiseRes<AdminLoginRes> => request.post("/user/add", data);
//部门管理
//部门列表
export const getDepartmentInfoList = (): PromiseRes<DepartmentInfoList> =>
  request.get("department/list");
//角色管理
//角色列表
export const getRoleInfoList = (): PromiseRes<RoleInfoList> =>
  request.get("role/list");
//菜单管理
//菜单列表
export const getMenuInfoList = (): PromiseRes<MenuInfoList> =>
  request.get("menu/list");
//上传
export const uploadPicture = (data: UploadData): PromiseRes<AdminLoginRes> =>
  request.post("/upload", data);

// 客户管理-新增客户
export const addNewCustomer = (
  data: AddNewCustomer
): PromiseRes<AdminLoginRes> => request.post("/customer/add", data);
// 客户管理-客户列表
export const getCustomerInfoList = (
  data: CustomerListParams
): PromiseRes<CustomerList> => request.post("/customer/list", data);
